#include "BatteryModule.h"
#include "ModuleManager.h"


bool BatteryModule::accept(ModuleRequest & request)
{
	BatteryModuleRequest& batteryRequest = (BatteryModuleRequest&) (request);
	this->accept(batteryRequest);
}

bool BatteryModule::accept(BatteryModuleRequest & request)
{
	char receiveBag[1];
	if (this->addr >= MIN_ADDR) {
		uint8_t actualSize = Wire.requestFrom((uint8_t)this->addr, (uint8_t)1);
		if (actualSize == 1) {
			if (Wire.readBytes(receiveBag, 1) == 1) {
				this->batteryPercent = receiveBag[0];
				return 1;
			}
		}
	}
	return 0;
}

BatteryModule::~BatteryModule()
{
}

uint8_t BatteryModule::getBatteryPercent(void) {
	return this->batteryPercent;
}
